package com.geyue.controller;

import com.geyue.common.toolbox.result.Res;
import com.geyue.core.model.User;
import com.geyue.core.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by Lyon on 2017/5/15.
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/",method = RequestMethod.GET)
    public String list(){
        return "user/list";
    }

    @RequestMapping(value = "/",method = RequestMethod.POST)
    @ResponseBody
    public Res list(User user, Integer pageSize,Integer pageNum){
        return Res.success("",userService.getPage(pageNum,pageSize,user));
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public String list(@PathVariable Integer id, Model model){

        model.addAttribute("userInfo",userService.getOneByKey(id));
        return "user/info";
    }
}
